<script>
	import RongIMLib from 'common/RongIMLib-3.0.5-dev.min.js'
	import store from '@/store/index.js'
	export default {
		onLaunch: function() {
			// 融云初始化
			var that = this;
			var RongIMClient = RongIMLib
			const im = RongIMClient.init({
				appkey: '25wehl3u20ntw'
			})
			console.log(im)
				store.state.im = im //存入本地
			//版本更新	
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				console.log(widgetInfo.versionCode)
				that.$Request.post(
					that.$api.httpApi.login.version, {
						version: widgetInfo.versionCode,
						type: 0
					}
				).then(res => {
					if (res.code == 0) {
						console.log(res.data)
						console.log(res.data.versiondata.newversion)

						if (res.data.version > widgetInfo.versionCode) {
							uni.showLoading({
								title: res.data.content
							})
							uni.downloadFile({
								url: res.data.url,
								success: (downloadResult) => {
									console.log(downloadResult.statusCode)
									if (downloadResult.statusCode === 200) {
										plus.runtime.install(downloadResult.tempFilePath, {
											force: true
										}, function() {
											plus.runtime.restart();
										}, function(e) {});
									}
								},
								complete: () => {
									uni.hideLoading();
								}
							});
						}

					}
				});

			});

			//	代码示例，此两项代码可以放到App.vue
			this.addJYJPushReceiveNotificationListener();
			this.addJYJPushReceiveOpenNotificationListener();
			this.addJYJPushReceiveBackgroudNotificationListener();
			this.addJYJPushCustomReceiveNotificationListener();

			setTimeout(function() {
				const jyJPush = uni.requireNativePlugin('JY-JPush');
				//获取极光注册id
				jyJPush.getRegistrationID(
					//  返回的数据会有registrationID，errorCode
					result => {
						uni.showToast({
							icon: 'none',
							title: JSON.stringify(result)
						})
					});
				jyJPush.setJYJPushAlias({
					userAlias: '3'
					}, result=> {
					//  设置成功或者失败，都会通过这个result回调返回数据；数据格式保持极光返回的安卓/iOS数据一致
					//  注：若没有返回任何数据，考虑是否初始化完成
					uni.showToast({
					icon:'none',
					title: JSON.stringify(result)
					})
				});
				jyJPush.getLastPushInfo(result => {
					if (result != null) {
						uni.showToast({
							icon: 'none',
							title: 'last' + JSON.stringify(result)
						})
					}
				});

			}, 500);


		},
		methods: {
			addJYJPushReceiveOpenNotificationListener() {
				const jyJPush = uni.requireNativePlugin('JY-JPush');
				jyJPush.addJYJPushReceiveOpenNotificationListener(result => {
					uni.showToast({
						icon: 'none',
						title: 'open' + JSON.stringify(result)
					})
					console.log('打开了' + JSON.stringify(result));
				});
			},
			addJYJPushReceiveNotificationListener() {
				const jyJPush = uni.requireNativePlugin('JY-JPush');
				jyJPush.addJYJPushReceiveNotificationListener(result => {
					uni.showToast({
						icon: 'none',
						title: 'rec' + JSON.stringify(result)
					})
					console.log('收到了' + JSON.stringify(result));
				});
			},
			addJYJPushReceiveBackgroudNotificationListener() {
				const jyJPush = uni.requireNativePlugin('JY-JPush');
				jyJPush.addJYJPushReceiveBackgroudNotificationListener(result => {
					uni.showToast({
						icon: 'none',
						title: 'recback' + JSON.stringify(result)
					})
					console.log('后台收到了' + JSON.stringify(result));
				});

			},
			addJYJPushCustomReceiveNotificationListener() {
				const jyJPush = uni.requireNativePlugin('JY-JPush');
				jyJPush.addJYJPushCustomReceiveNotificationListener(result => {
					uni.showToast({
						icon: 'none',
						title: 'ReceiveCustomNotificationListener' + JSON.stringify(result),
					})


				});
			}
		},
		onShow: function() {

		},
		onHide: function() {

		}
	}
</script>

<style>
	/*每个页面公共css */
	uni-page-body,
	#app {
		height: 100%;
	}

	html {
		background: #FAFAFE;
	}

	div {
		font-size: 28upx;
	}

	.font24 {
		font-size: 24upx;
	}

	.font26 {
		font-size: 26upx;
	}

	.font30 {
		font-size: 30upx;
	}

	.font32 {
		font-size: 32upx;
	}

	.flex-row {
		display: flex;
		flex-direction: row;
	}

	.flex-col {
		display: flex;
		flex-direction: column;
	}
	.red{color: red;}

	/* 隐藏滚动条 */

	/deep/.uni-scroll-view {
		background: transparent;
	}

	/deep/.uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none
	}

	/* .uni-page-head
	{
		border-bottom: 1upx solid rgba(238,238,238,1);
	} */
	.text-ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		/* display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical; */
	}

	.text-ellipsis2 {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.text-ellipsis3 {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
	}

	.flex-between {
		justify-content: space-between;
		align-items: center;
	}

	.textCenter {
		text-align: center;
	}

	.textR {
		text-align: right;
	}

	.mgTop5 {
		margin-top: 5px;
	}

	.mgTop10 {
		margin-top: 20upx;
	}

	.mgTop20 {
		margin-top: 20upx;
	}

	.mgTop30 {
		margin-top: 30upx;
	}

	.mgTop40 {
		margin-top: 40upx;
	}

	.mgTb20 {
		margin: 20upx 0;
	}

	.mgTb40 {
		margin: 40upx 0;
	}

	.paddingtb20 {
		padding: 20upx 0;
	}

	.width60 {
		width: 60%;
	}

	.color66 {
		color: #666666;
	}
	.colorf{
		color: #FFFFFF;
		
	}
	.bold{
		font-weight: bold;
	}
	.yell{
		color: #fd580a;
	}
	.font40{
		font-size: 40upx;
	}
		
	.color9{
		color: #999999;
	}
</style>
